package edu.ynu.se.xiecheng.achitectureclass.common.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebConfig implements WebMvcConfigurer {

    @Override
    public void addCorsMappings(CorsRegistry registry) {
        // 允许所有的请求进行跨域
        registry.addMapping("/**") // 所有的路径都允许跨域
                .allowedOrigins("http://localhost:8081")  // 允许来自特定域的跨域请求

                .allowedMethods("GET", "POST", "PUT", "DELETE")  // 允许的方法
                .allowedHeaders("*"); // 允许的请求头
    }
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        // 将 'camera_images' 映射为公开的 URL 路径
        registry.addResourceHandler("/camera_images/**")  // 前端访问路径
                .addResourceLocations("file:/D:/Users/limi/WebstormProjects/achitecture/achitecture/camera_images/");  // 服务器本地路径
    }
}
